#ifndef HTTP_DEMO_H
#define HTTP_DEMO_H

#include <QWidget>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QFile>
#include <QTime>

QT_BEGIN_NAMESPACE
namespace Ui { class HTTP_Demo; }
QT_END_NAMESPACE

class HTTP_Demo : public QWidget
{
    Q_OBJECT

public:
    HTTP_Demo(QWidget *parent = nullptr);
    ~HTTP_Demo();

    //时间格式化输出
    QString timeFormat(qint64  seconds);
    //速度格式化输出
    QString speed(double speed);
  //已经下载的大小格式化输出
    QString size(qint64 bytes);

    //计算下载进度各种数据，实时下载速度，已下载大小，剩余时间等
    void calculateDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);

    void stopWork();
private slots:
    //使用缺省值默认路径触发
    void on_pushButton_defaultPath_clicked();
    //选择文件夹路径触发
    void on_pushButton_selectFilePath_clicked();
    //下载按钮触发
    void on_pushButton_download_clicked();

    //下载完成后的槽
    void onFinish();
    void onReadyRead();
    void onDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
    void on_pushButton_pause_clicked();

    void on_pushButton_start_clicked();

private:
    Ui::HTTP_Demo *ui;

    QNetworkAccessManager *mNetworkManager = nullptr; //网络管理
    QNetworkReply *mPReply = nullptr; //网络响应
    QTime m_timeRecord; //记录下载实时网速用时
    int m_timeInterval= 0; //时间记录的间隔差距

    qint64 m_bytesReceived = 0; ///当前的接收数据大小
    qint64 m_bytesTotal = 0;  ///当前下载的数据总大小
    qint64 m_currentDownloadSize = 0; ///当前已经下载的大小
    qint64 m_intervalDownloadSize = 0; ///计算速度之前下载的大小的累计和，计算速度用

    //新增---
    bool m_isStop = true; //使用点击了暂停按钮
    qint64 m_bytesCurrentReceived  = 0;
    bool m_isSupportBreakPoint = true;
    QString m_fileName;
    QByteArray m_ReplyData;

};
#endif // HTTP_DEMO_H
